#!/bin/sh

# This sets the entitlements on the programs passed in so they can be
# debugged and generate core dumps.
#
# To run this in a libtool environment, do:
#
#  ./libtool execute ../macos-entitle <executable>

ENTITLEMENTS=tmp.entitlements
if [ ! -e "$ENTITLEMENTS" ]; then
    /usr/libexec/PlistBuddy -c \
	"Add :com.apple.security.get-task-allow bool true" $ENTITLEMENTS
    /usr/libexec/PlistBuddy -c \
	"Add :com.apple.security.cs.disable-library-validation bool true" $ENTITLEMENTS
    /usr/libexec/PlistBuddy -c \
	"Add :com.apple.security.cs.allow-unsigned-executable-memory bool true" $ENTITLEMENTS
    /usr/libexec/PlistBuddy -c \
	"Add :com.apple.security.get-task-allow bool true" $ENTITLEMENTS
    /usr/libexec/PlistBuddy -c \
	"Add :com.apple.security.cs.allow-dyld-environment-variables bool true" $ENTITLEMENTS
fi
codesign -s - -f --entitlements "$ENTITLEMENTS" $*
